package com.uum.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uum.admin.pojo.query.OperationPageQuery;
import com.uum.admin.service.SysOperationLogService;
import com.uum.common.core.annotation.Operation;
import com.uum.common.core.entity.SysOperationLog;
import com.uum.common.core.enums.BusinessType;
import com.uum.common.core.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Api(tags = "操作日志接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/operation")
public class SysOperationLogController {

    private final SysOperationLogService operationLogService;

    @Operation(description = "查询操作日志",businessType = BusinessType.QUERY,isSaveResponseData = false)
    @ApiOperation(value = "操作日志列表")
    @GetMapping("page")
    public Result pageForOperationLog(OperationPageQuery query) {
        IPage result = operationLogService.page(query);
        return Result.success(result);
    }

    @ApiOperation(value = "添加操作日志")
    @PostMapping("add")
    public Result addOperationLog(@RequestBody SysOperationLog operationLog) {
        boolean save = operationLogService.save(operationLog);
        return Result.judge(save);
    }

    @ApiOperation(value = "删除操作日志")
    @DeleteMapping("delete/{ids}")
    public Result deleteOperationLog(@PathVariable String ids) {
        operationLogService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.success();
    }
}

